package munci.core;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

import munci.core.words.Basic;
import munci.core.words.Literals;
import munci.core.words.Operators;
import munci.core.words.Types;
import munci.read.ReaderTokenizer;

public class Console {
	public static void main (String[] args) throws IOException, ClassNotFoundException {

		final Context env = Context.get();
		Basic.addWords(env);
		env.dict().scan(Literals.class).scan(Operators.class).scan(Types.class);
		env.pushDict();

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in)) {
					int read = 0;
					public int read(char[] cbuf, int off, int len) throws IOException {
						if (read >= 0) System.out.print(env.toString() + ">");
						return (read = super.read(cbuf, off, len));
					}
				};
		
		while (true) { // iterates once per exception
			try {
				env.interpret(new ReaderTokenizer(br, "console"));
			} catch (Throwable ex) {
				ex.printStackTrace();
			}
		}
	}
}
